package com.atguigu.gmall.controller;

import com.atguigu.gmall.client.service.CartFeignClientService;
import com.atguigu.gmall.client.service.ProductFeignClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
public class WebCartController {

    @Autowired
    private ProductFeignClientService productFeignClientService;
    @Autowired
    private CartFeignClientService cartFeignClientService;

    //    'http://cart.gmall.com/addCart.html?skuId=' + this.skuId + '&skuNum=' + this.skuNum
    @RequestMapping("addCart.html")
    public String addCart(@RequestParam Long skuId, @RequestParam Integer skuNum, HttpServletRequest request) {
        //并没有传入用户Id？
        cartFeignClientService.addToCart(skuId, skuNum);
        //页面需要skuNum, skuInfo
        request.setAttribute("skuInfo", productFeignClientService.getSkuInfo(skuId));
        request.setAttribute("skuNum", skuNum);
        return "cart/addCart";
    }

    @RequestMapping("cart.html")
    public String cartList(){
        return "cart/index";
    }



}
